package org.snia.cdmi.model;

import java.util.HashMap;
import java.util.Map;

public class DataObjectWithAcl extends BaseDataObject {

	/** 对象的acl列表 */
	private Map<String, String> acl;


	/**
	 * Create a container without any name specified
	 */
	public DataObjectWithAcl() {
	}

	/**
	 * @param acl
	 *            the acl to set
	 */
	public void setAccessControlList(Map<String, String> acl) {
		this.acl = acl;
	}

	/**
	 * @return the acl
	 */
	public Map<String, String> getAccessControlList() {
		if (acl == null) {
			acl = new HashMap<String, String>();
		}
		return acl;
	}

	public void setAccessControlPolicy(AccessControlList acl) {
		if (this.acl == null) {
			this.acl = new HashMap<String, String>();
		}

		for (Grant gap : acl.getGrants()) {
			if (gap.getPermission().equals(Permission.NULL)) {
				this.acl.remove(gap.getGrantee().getIdentifier());
			} else {
				this.acl.put(gap.getGrantee().getIdentifier(), gap
						.getPermission().toString());
			}
		}
	}

	public String getAccessControlPolicy(String key) {
		return this.acl.get(key);
	}
}
